Connect multiple camera to raspberry pi
Table of Content
Connect multiple camera to raspberry pi#
| hardware list | |
|---|---|
| rpi-4 | |
| arducam uc-475 | |
| rpi camera-v2 |
link#
Hardware connection#


pi camera#
raspberry pi camera v2
| camera | Spec |
|---|---|
| sensor | IMX219 |
| 8M 3280*2646 | |
| 1080p30, 720p60, 640*480p90 |
OS and settings#
Download raspberry pi 64bit lite edition os Raspberry Pi OS (64-bit)
config#
rasbian first config Connect rpi to hdmi for first config
run sudo raspi-config to:
- Enabled ssh
- Set WIFI
config arducam#
sudo nano /boot/config.txt
#Find the line "camera_auto_detect=1" and modify it:
camera_auto_detect=0
# Add camera config
[all]
#dtoverlay=camera-mux-4port,cam0-<camera sensor name>,cam1-<camera sensor name>,cam2-<camera sensor name>,cam3-<camera sensor name>
# Add three camera
dtoverlay=camera-mux-4port,cam0-imx219,cam1-imx219,cam2-imx219
Please manually add the number of cam according to the number of cameras you have connected. Example: if you have three IMX219 cameras connected, enter:
imx219: Raspberry camera v2
dtoverlay=camera-mux-4port,cam0-imx219,cam1-imx219,cam2-imx219
Boot to load new settings
Capture camera#
view camera
libcamera-still -t 0 --camera <choose camera num>
| arguments | |
|---|---|
| –camera | camera index (zero base) |
| -t | application run time in msec (0 forever) |
streaming#
Introducing the Raspberry Pi Cameras
TODO#
- libcamera-raw
- camera control: control camera settings
libcamera to stdout
libcamera-vid -t 0 -n --inline -o -
Stream using libcamera-vid#
pi
libcamera-vid -t 0 --inline --listen --width 1280 --height 720 -b 15000000 --profile high --level 4.2 --framerate 30 -o tcp://0.0.0.0:3333
pc
gst-launch-1.0 tcpclientsrc host=10.100.102.32 port=3333 \
! h264parse \
! avdec_h264 \
! autovideosink sync=true
pi
libcamera-vid -t 0 --inline --listen --width 1280 --height 720 -b 15000000 --profile high --level 4.2 --framerate 30 -o udp://10.100.102.16:3333
gst-launch-1.0 udpsrc port=3333 \
! h264parse \
! avdec_h264 \
! autovideosink sync=false
libcamera and gstreamer#
using pipe and fdsrc
pi
libcamera-vid -t 0 -n --inline -o - | gst-launch-1.0 fdsrc fd=0 ! udpsink host=10.100.102.16 port=3333
pc
gst-launch-1.0 udpsrc port=3333 \
! h264parse \
! avdec_h264 \
! autovideosink sync=false
pi with camera index
libcamera-vid -t 0 -n --camera 0 --inline -o - \
| gst-launch-1.0 fdsrc fd=0 \
! udpsink host=10.100.102.16 port=3333
| arguments | |
|---|---|
| -t | application run time in ms (0 forever) |
| -n | no preview |
| –camera | camera index (zero base) |
| –online | Force PPS/SPS header with every I frame (h264 only) todo: ??? |
| -o | out (- stdout) |
libcamera-tools#
sudo apt install libcamera-tools
cam -l
libcamerasrc#
sudo apt install gstreamer1.0-libcamera
camera_name
cam util install by libcamera-tools
cam -l
Available cameras:
1: 'imx219' (/base/soc/i2c0mux/i2c@1/pca@70/i2c@0/imx219@10)
2: 'imx219' (/base/soc/i2c0mux/i2c@1/pca@70/i2c@1/imx219@10)
3: 'imx219' (/base/soc/i2c0mux/i2c@1/pca@70/i2c@2/imx219@10)
libcamerasrc camera_name use the full name
/base/soc/i2c0mux/i2c@1/pca@70/i2c@0/imx219@10
pi
gst-launch-1.0 libcamerasrc camera_name="/base/soc/i2c0mux/i2c@1/pca@70/i2c@0/imx219@10" \
! video/x-raw,colorimetry=bt709,format=NV12,width=1280,height=720,framerate=30/1 \
! x264enc tune=zerolatency bitrate=500 speed-preset=superfast \
! rtph264pay \
! udpsink host=10.100.102.16 port=5000
pc
gst-launch-1.0 udpsrc port=5000 \
caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" \
! rtph264depay \
! decodebin \
! videoconvert ! autovideosink
libcamera-raw#
not-working for know
h264, libav, mjpeg or yuv420
libcamera-raw - t 1000 -n --codec yuv420 --framerate 30 --camera 1 -o - | gst-launch-1.0 fdsrc ! video/x-raw,width=640,height=480,framerate=30/1,format="I420" \
! videoconvert ! video/x-raw,format=RGB \
! x264enc tune=zerolatency bitrate=500 speed-preset=superfast \
! rtph264pay \
! udpsink host=10.100.102.16 port=5000
Streaming test pipe#
gst-launch-1.0 videotestsrc \
! video/x-raw,framerate=20/1 \
! videoscale \
! videoconvert \
! x264enc tune=zerolatency bitrate=500 speed-preset=superfast \
! rtph264pay \
! udpsink host=127.0.0.1 port=5000
pc
gst-launch-1.0 udpsrc port=5000 \
caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" \
! rtph264depay \
! decodebin \
! videoconvert ! autovideosink
TODO#
- check camera index (it’s reverse to camera port name in card)